<template>
  <div class="login">
    <el-form
      :model="dynamicValidateForm"
      ref="dynamicValidateForm"
      label-width="100px"
      class="demo-dynamic"
    >
      <el-form-item
        prop="email"
        label="用户名"
      >
        <el-input v-model="dynamicValidateForm.email"></el-input>
      </el-form-item>
      <el-form-item
        v-for="(domain, index) in dynamicValidateForm.domains"
        :label="'密码'"
        :key="domain.key"
        :prop="'domains.' + index + '.value'"
        :rules="{
          required: true,
          message: '密码不能为空',
          trigger: 'blur',
        }"
      >
        <el-input v-model="domain.value" type="password" ></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('dynamicValidateForm')">登录</el-button>
        <el-button @click="addDomain">注册</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dynamicValidateForm: {
        domains: [
          {
            value: "",
          },
        ],
        email: "",
      },
    };
  },
  methods: {
    submitForm() {
      let name = this.dynamicValidateForm.email
      let pwd = this.dynamicValidateForm.domains[0].value
      console.log(name,pwd);
      this.axios.post("/api/login",{name,pwd}).then((res)=>{
        console.log(res.data);
        if(res.data.code==200){
          alert(res.data.msg)
          window.location.href="http://localhost:8080/"
        }else{
          alert(res.data.msg)
        }
      })
    },
    addDomain() {
      
    },
  },
};
</script>

<style lang="scss" scoped>
.login{
  width: 500px;
  margin: 100px auto;
}
</style>